package Components;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import Connector.Connector;
import Game.*;

public class TetrisPlayground extends JPanel{
	
	private GameWindow motherWindow;
	private Tetris myTetris;
	private Tetris enemy;
	private Image background;
	private int width, heigh;
	
	private String DIR = "picture/playground_pics/";
	
	public TetrisPlayground(GameWindow mW, int w, int h) {
		this.motherWindow = mW;
		this.width = w;
		this.heigh = h;
		try {
			this.background = ImageIO.read(new File(DIR+"bgm.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		this.setLayout(null);
		this.setVisible(true);
		this.setSize(new Dimension(width, heigh));
		this.repaint();
		
		myTetris = new Tetris(this, this.motherWindow.getConnection());
		enemy = new Tetris(this,this.motherWindow.getConnection());
		
		myTetris.setBounds(100, 10, myTetris.getSizeX() - 7, myTetris.getSizeY() + 3);
		enemy.setBounds(400, 10, myTetris.getSizeX() - 7, myTetris.getSizeY() + 3);
		
		this.add(myTetris);
		this.add(enemy);
		
		//motherWindow.addKeyListener(myTetris);		
		//myTetris.start();	
	}
	
	public Tetris getTetris() {
		return myTetris;
	}
	
	
	public void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		
		g2.drawImage(background, 0, 0, null);
		
	}
	
	public int getMyScore() {
		return myTetris.getUserScore();
	}
	
	public int getEnemyScore() {
		return enemy.getUserScore();
	}
	
	public GameWindow getMother() {
		return this.motherWindow;
	}
	
	public Tetris getMyTetris() {
		return this.myTetris;
	}
	
	public Tetris getEnemy() {
		return enemy;
	}

}
